﻿using Microsoft.Extensions.DependencyInjection;
using Modules.Person.Repositories;
using PmSoft;

namespace Modules.Person;

[UseDI(ServiceLifetime.Scoped)]
public class PersonCertificateService
{
    private readonly PersonCertificateRepository personCertificateRepository;
    private readonly PersonCertificateSpecialityService personCertificateSpecialityService;

    public PersonCertificateService(PersonCertificateRepository personCertificateRepository, PersonCertificateSpecialityService personCertificateSpecialityService)
    {
        this.personCertificateRepository = personCertificateRepository;
        this.personCertificateSpecialityService = personCertificateSpecialityService;
    }

    public void Create(PersonCertificate entity)
    {
        personCertificateRepository.Insert(entity);
    }

    public void Deleted(IEnumerable<string> ids)
    {
        foreach (string id in ids)
        {
            Delete(id);
        }
    }

    public void Delete(string id)
    {
        personCertificateRepository.DeleteByEntityId(id);
    }

    public IEnumerable<PersonCertificate> GetPersonCertificatesByPersonId(int personId)
    {
        return personCertificateRepository.GetPersonCertificatesByPersonId(personId);
    }

    public void DeleteByPersonId(int personId)
    {
        IEnumerable<PersonCertificate> personCertificates = GetPersonCertificatesByPersonId(personId);
        Deleted(personCertificates.Select(a => a.Id));
    }
}